﻿@model FC.Data.ViewModels.Contests.ProblemContent

@{
    Layout = "~/Views/Shared/_ManagerLayout.cshtml";
}

@using (Ajax.BeginForm(
        "SaveProblem",
        "Manager",
        new AjaxOptions()
        {
            OnSuccess = "Success",
            OnFailure = "Failure"
        }
    ))
{
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
        <h2>@ViewBag.Title</h2>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.Examples[0].Id)
        @Html.HiddenFor(model => model.CollectionCode)
        <div class="form-group">
            @Html.LabelFor(model => model.No, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.No, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.No, "", new { @class = "text-danger" })
            </div>
            @Html.LabelFor(model => model.Score, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.Score, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Score, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Title, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Description, new { @class = "form-control", style = "height:100px;", rows=10 })
                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.InputFormat, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.InputFormat, new { @class = "form-control", style = "height:100px;", rows = 10 })
                @Html.ValidationMessageFor(model => model.InputFormat, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.OutputFormat, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.OutputFormat, new { @class = "form-control", style = "height:100px;", rows = 10 })
                @Html.ValidationMessageFor(model => model.OutputFormat, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Examples[0].InputExample, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Examples[0].InputExample, new { @class = "form-control", style = "height:100px;", rows = 10 })
                @Html.ValidationMessageFor(model => model.Examples[0].InputExample, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Examples[0].OutputExample, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Examples[0].OutputExample, new { @class = "form-control", style = "height:100px;", rows = 10 })
                @Html.ValidationMessageFor(model => model.Examples[0].OutputExample, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Tips, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextAreaFor(model => model.Tips, new { @class = "form-control", style = "height:100px;", rows = 10 })
                @Html.ValidationMessageFor(model => model.Tips, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Convention, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Convention, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Convention, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Keyword, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.Keyword, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Keyword, "", new { @class = "text-danger" })
            </div>
            @Html.LabelFor(model => model.TimeLimit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.TimeLimit, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TimeLimit, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.MemoryLimit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.MemoryLimit, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.MemoryLimit, "", new { @class = "text-danger" })
            </div>
            @Html.LabelFor(model => model.CodeLengthRestriction, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.CodeLengthRestriction, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CodeLengthRestriction, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TestProcedure, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.TestProcedure, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TestProcedure, "", new { @class = "text-danger" })
            </div>
            @Html.LabelFor(model => model.Author, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.Author, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Author, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Link, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.TextBoxFor(model => model.Link, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Link, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10" style="text-align:center">
                <button id="Save" type="submit" class="btn btn-success" style="margin-right:30px;">保 存</button>
                <a class="btn btn-default" href="~/Manager/Problems/@ViewBag.Collection">返 回</a>
            </div>
        </div>
    </div>
}

@section Script{
    <script>
        function Success(result) {
            if (result.state == "ok") {
                alert("保存成功");
                window.location = "/Manager/Problems/@ViewBag.Collection";
            }
            else {
                alert(result.message);
            }
        }
        function Failure() {
            alert("保存失败");
        }
    </script>
}